package com.zhentao.service.impl;

import com.zhentao.service.YzmService;
import com.zhentao.util.SmsSendUtil;
import com.zhentao.util.Yzmtil;
import io.minio.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/yzm")
@CrossOrigin
public class sjhyzController {
    @Autowired
     private YzmService yzmService;
    @Autowired
    RedisTemplate<String,String> redisTemplate;

    @RequestMapping("/get")
    public Result get(String phone){
        String coders = redisTemplate.opsForValue().get(phone);
        System.err.println(coders+"手机号验证码");
        if (!ObjectUtils.isEmpty(coders)){
//            return new Result(true,"验证码发送成功");
        }
        coders = String.valueOf(Yzmtil.generateValidateCode(6));
        //发送短信服务
        boolean send = SmsSendUtil.sendSms(phone, coders);
        if (send){
            //存入redis当中
            redisTemplate.opsForValue().set(phone,coders,5, TimeUnit.MINUTES);
//            return new Result(true,"验证码发送成功");
        }
        return null;
    }

}























